package com.kevin.mapping.script.lexer;

import com.kevin.mapping.script.engine.JSONEnv;

import java.math.BigDecimal;

public class StrValue extends Token {

    private String value;

    public StrValue(int type, String content) {
        super(type);
        this.value = content;
    }

    public String toString() {
        return "value=" + value + " type=" + (char) type;
    }

    public String getValue(JSONEnv env) {
        return value;
    }

    public void setValue(String value) {
        this.value = value;
    }


    @Override
    public Integer getIntValue(JSONEnv env) {
        try {
            return Integer.valueOf(value);
        } catch (Exception e) {
            return null;
        }

    }

    @Override
    public Long getLongValue(JSONEnv env) {
        try {
            return Long.parseLong(value);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public Double getDoubleValue(JSONEnv env) {
        try {
            return Double.valueOf(value);
        } catch (Exception e) {
            return null;
        }
    }

    @Override
    public BigDecimal getBigDecimalValue(JSONEnv env) {
        try {
            return BigDecimal.valueOf(Long.parseLong(value));
        } catch (Exception e) {
            return null;
        }

    }

    @Override
    public String getStrValue(JSONEnv env) {
        return value;
    }

    @Override
    public Object getObjectValue(JSONEnv env) {
        return getValue(env);
    }
}
